<?php



namespace App\Zesow\Cache\Impl;

use Illuminate\Support\Facades\Cache;
use App\Services\Other\Interfaces\SliderServiceInterface;

class SliderCache
{

    public const KEY_NAME = 'sliders';

    private $sliderService;

    public function __construct(SliderServiceInterface $sliderService)
    {
        $this->sliderService = $sliderService;
    }

    public function get()
    {

            if (Cache::has(self::KEY_NAME)) {
                return  Cache::get(self::KEY_NAME);
            }
            $sliders  = $this->sliderService->all();
            Cache::put(self::KEY_NAME, $this->sliderService->all());
            return  $sliders;


    }

    public function destroy(): void
    {
        Cache::forget($this->key());
    }


    private function key(): string
    {
        return self::KEY_NAME ;
    }


}
